package cn.larry.tools.weixin;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * Larry
 * 2022/2/14 13:17
 *
 * @Version 1.0
 */
public class WXPayConfigImpl extends WXPayConfig {

    private String appId;
    private String mchId;
    private String key;
    private String certPath;

    public WXPayConfigImpl(String appId, String mchId, String key, String certPath) {
        this.appId = appId;
        this.mchId = mchId;
        this.key = key;
        this.certPath = certPath;
    }

    /**
     * 获取 App ID
     *
     * @return App ID
     */
    @Override
    public String getAppID() {
        return appId;
    }

    /**
     * 获取 Mch ID
     *
     * @return Mch ID
     */
    @Override
    public String getMchID() {
        return mchId;
    }

    /**
     * 获取 API 密钥
     *
     * @return API密钥
     */
    @Override
    public String getKey() {
        return key;
    }

    /**
     * 获取商户证书内容
     *
     * @return 商户证书内容
     */
    @Override
    InputStream getCertStream() {
        try {
            return new FileInputStream(new File(certPath));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 获取WXPayDomain, 用于多域名容灾自动切换
     *
     * @return
     */
    @Override
    IWXPayDomain getWXPayDomain() {
        return new IWXPayDomainImpl();
    }

}
